(ns clj.ex3)
(import '(com.aligotec Address User))


(defn test3 [& args]
  (println "Playing in first test3 - recursive bean " args)
  (let [user (doto (User.) (.setName "Bill") (.setBirth "2000-01-01") (.setAddress (doto (Address.)  (.setNumber 104) (.setStreet "street-1") (.setTown "Bucharest") )) )]
    (.. user (getAddress) (setCountry "Romania"))
    (doto user
      (.addProp "k1" "v1")
      (.addProp "k2" "v2"))
    
    (println "Created user " user)
    
    (def user-bean (bean user))
    (println "Created bean " user-bean)
    
    (defn deep-bean [j-obj]
      ;will recursivly bean the j-obj java object
      (println "deep-bean on " j-obj)
      (def the-bean (bean j-obj))
      
      (doall (map 
               #(try 
                  (if-not (.. (the-bean %) getClass getName (startsWith "java.lang"))
                    (def the-bean (assoc the-bean % (deep-bean (the-bean %))) ) )
                  (catch Exception e ))
               (keys the-bean)))
     
      (println "-" the-bean)
      the-bean)
    
    (println "\n---\n")
    
    (def user-bean1 (deep-bean user))
    
    (println "\n---\n")
    
    (println "Deep bean " user-bean1)
    
    (println "accessing street: " (:street (user-bean1 :address)))
    
    )
  
  "test1 finished")


;(defn my-f 
;  ([x] (my-f x (bean x))
;  ([x  y] (..... (my-f y (bean ))
;  ))
;  
;  (defn reduce [coll red-fn]
;    (let [statefull-reduce (fn [initial-coll coll result]  
;                              (statefull-reduce initial-coll (rest coll) (red-fn (first coll) result)))]
;      (statefull-reduce coll coll 0)
;    ) ;; coll = [1 2 3 4]
          
       